package springcloud_eureka_ribbon_consumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/*
 * 提供入口供外部调用
 */
@RestController
public class ConsumerController {
    @Autowired
    RestTemplate restTemplate;
	//注解映射请求路径
    @RequestMapping("/hello")
    public String hello() {
		//进行远程调用
	    return restTemplate.getForObject("http://springcloud-eureka-ribbon-consumer23/hello/?name=yao", String.class);
	}
    
    @Autowired
    Remote remote;
	
    @RequestMapping("/hello/{name}")
  //可以将URL中占位符参数{xxx}绑定到处理器类的方法形参中@PathVariable("xxx")
    public String index(@PathVariable("name") String name) {
    	System.out.println("接受到请求参数:"+name+",进行转发到其他服务!");
        return remote.hello(name);
    }
}